﻿/*
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * See product pages for more information.
 * http://closesudoku.codeplex.com
 * Copyright (C), 2010, hrondra
 */


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

using System.Xml;
using System.Xml.XPath;
using System.IO;
using System.Resources;
using System.Reflection;

namespace Close.Classes
{
    public class ThemeClass
    {
        private static readonly ThemeClass _settings = new ThemeClass();

        /// <summary>
        /// Singleton - configuration from xml file.
        /// </summary>
        public static ThemeClass Settings
        {
            get
            {
                return _settings;
            }
        }

        private ThemeClass()
        {
            

            String full_path = System.Reflection.Assembly.GetCallingAssembly().GetName().CodeBase;
            String directory_path = full_path.Substring(0, full_path.LastIndexOf("\\"));
            String pth = Path.Combine(directory_path, "Settings\\config.xml");


            XmlTextReader textReader = new XmlTextReader(pth);
            XmlDocument xdoc = new XmlDocument();

            try
            {
                xdoc.Load(textReader);
                textReader.Close();

                XmlElement koren = xdoc.DocumentElement;

                AutoSizeWidth = AutoSizeHeight = true;
                if (koren.SelectNodes("//display/height").Count != 0)
                {
                    _currentDisplayHeight = Convert.ToInt32(koren.SelectNodes("//display/height")[0].InnerText);
                    AutoSizeHeight = false;
                }
                if (koren.SelectNodes("//display/width").Count != 0)
                {
                    _currentDisplayWidth = Convert.ToInt32(koren.SelectNodes("//display/width")[0].InnerText);
                    AutoSizeWidth = false;
                }

                _currentDisplayMode = Convert.ToByte(koren.SelectNodes("//display/mode")[0].InnerText);
                if(koren.SelectNodes("//display/language").Count != 0)
                    _enforcedLanguage = Convert.ToString(koren.SelectNodes("//display/language")[0].InnerText);
                _buttonsPanelHeight = Convert.ToInt32(koren.SelectNodes("//numpad/height")[0].InnerText);
                _boardBackground = Fluid.Classes.Theme.ThemeClass.HexStringToColor(koren.SelectNodes("//background/implicit")[0].InnerText);
                _boardBackgroundSelected = Fluid.Classes.Theme.ThemeClass.HexStringToColor(koren.SelectNodes("//background/selected")[0].InnerText);
                _boardBackgroundImprinted = Fluid.Classes.Theme.ThemeClass.HexStringToColor(koren.SelectNodes("//background/imprinted")[0].InnerText);
                _boardBackgroundLast = Fluid.Classes.Theme.ThemeClass.HexStringToColor(koren.SelectNodes("//grid/background/last")[0].InnerText);
                //TODO: dodelat barvy menu
                /*
                _listboxBackground
                _listboxBackgroundSelected
                _listboxForeColor
                _listboxForeColorSelected
                */
                _popMenuHeight = Convert.ToInt32(koren.SelectNodes("//popupmenu/height")[0].InnerText);
                _popMenuSmallWidth = Convert.ToInt32(koren.SelectNodes("//popupmenu/smallwidth")[0].InnerText);

                //same color as numbers
                _numpadBackroundColor = Fluid.Classes.Theme.ThemeClass.HexStringToColor(koren.SelectNodes("//numpad/backround/implicit")[0].InnerText);
                _numpadPressedBackroundColor = Fluid.Classes.Theme.ThemeClass.HexStringToColor(koren.SelectNodes("//numpad/backround/selected")[0].InnerText);
                _numpadForeColor = Fluid.Classes.Theme.ThemeClass.HexStringToColor(koren.SelectNodes("//numpad/forecolor/implicit")[0].InnerText);

                _numpadForeColor = Fluid.Classes.Theme.ThemeClass.HexStringToColor(koren.SelectNodes("//numpad/forecolor/implicit")[0].InnerText);

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(Close.Properties.Resources.NonCriticalDescription + ex.Message, Close.Properties.Resources.NonCritical);
            }            
        }

        public bool AutoSizeHeight { get; set; }
        public bool AutoSizeWidth { get; set; }
        
        private int _currentDisplayWidth = 240;
        /// <summary>
        /// Total display witdh.
        /// </summary>
        public int DisplayWidth
        {
            get 
            {                
                return _currentDisplayWidth;
            }
            set
            {
                _currentDisplayWidth = value;
            }
        }

        private int _currentDisplayHeight = 268;
        /// <summary>
        /// Total display height.
        /// </summary>
        public int DisplayHeight
        {
            get
            {
                return _currentDisplayHeight;
            }
            set 
            {
                _currentDisplayHeight = value;
            }
        }

        private byte _currentDisplayMode = 1;

        public enum DisplayModes : byte { Mixed = 1, SingleNumber = 2, Popup = 3 }
        /// <summary>
        /// Total display witdh.
        /// </summary>
        public DisplayModes DisplayMode
        {
            get
            {

                return (DisplayModes) _currentDisplayMode;
            }
        }

        private int _buttonsPanelHeight = 100;
        /// <summary>
        /// Bottom buttons height.
        /// </summary>
        public int ButtonsPanelHeight
        {
            get
            {
                return _buttonsPanelHeight;
            }
        }

        private Color _boardBackground = Color.White;
        /// <summary>
        /// Implicit background color of board.
        /// </summary>
        public Color BoardBackground
        {
            get
            {
                return _boardBackground;
            }
        }

        private Color _boardBackgroundSelected = Color.MediumSlateBlue;
        /// <summary>
        /// Selected row/column background color of board.
        /// </summary>
        public Color BoardBackgroundSelected
        {
            get
            {
                return _boardBackgroundSelected;
            }
        }
        private Color _boardBackgroundImprinted = Color.Silver;
        /// <summary>
        /// Not modifiable pane color.
        /// </summary>
        public Color BoardBackgroundImprinted
        {
            get
            {
                return _boardBackgroundImprinted;
            }
        }

        private Color _boardBackgroundLast = Color.Silver;
        /// <summary>
        /// Not modifiable pane color.
        /// </summary>
        public Color BoardBackgroundLast
        {
            get
            {
                return _boardBackgroundLast;
            }
        }

        private Color _listboxBackground = Color.Black;
        /// <summary>
        /// Values in listbox menu.
        /// </summary>
        public Color ListboxBackground
        {
            get
            {
                return _listboxBackground;
            }
        }
        private Color _listboxBackgroundSelected = Color.Silver;
        /// <summary>
        /// Values in listbox menu.
        /// </summary>
        public Color ListboxBackgroundSelected
        {
            get
            {
                return _listboxBackgroundSelected;
            }
        }

        private Color _listboxForeColor = Color.White;
        /// <summary>
        /// Values in listbox menu.
        /// </summary>
        public Color ListboxForeColor
        {
            get
            {
                return _listboxForeColor;
            }
        }

        private Color _listboxForeColorSelected = Color.Black;
        /// <summary>
        /// Values in listbox menu.
        /// </summary>
        public Color ListboxForeColorSelected
        {
            get
            {
                return _listboxForeColorSelected;
            }
        }

        private int _popMenuHeight = 20;
        /// <summary>
        /// Popup menu from right in game.
        /// </summary>
        public int PopMenuHeight
        {
            get
            {
                return _popMenuHeight;
            }
        }

        private int _popMenuSmallWidth = 20;
        /// <summary>
        /// Popup menu from right in game.
        /// </summary>
        public int PopMenuSmallWidth
        {
            get
            {
                return _popMenuSmallWidth;
            }
        }

        private Color _numpadBackroundColor = Color.Black;
        public Color NumpadBackroundColor
        {
            get
            {
                return _numpadBackroundColor;
            }
        }

        private Color _numpadPressedBackroundColor = Color.DarkBlue;
        public Color NumpadPressedBackroundColor
        {
            get
            {
                return _numpadPressedBackroundColor;
            }
        }
        private Color _numpadForeColor = Color.White;
        public Color NumpadForeColor
        {
            get
            {
                return _numpadForeColor;
            }
        }
        private String _enforcedLanguage = String.Empty;
        public String EnforcedLanguage
        {
            get
            {
                return _enforcedLanguage;
            }
        }

    }
}
